// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net) and Silicon Studio Corp. (https://www.siliconstudio.co.jp)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.

using Stride.Core.Yaml;
using Stride.Core.Yaml.Events;
using Stride.Core.Yaml.Serialization;

namespace Stride.Core.Assets.Serializers;

/// <summary>
/// A Yaml serializer for <see cref="PackageVersion"/>
/// </summary>
[YamlSerializerFactory(YamlAssetProfile.Name)]
internal class UriYamlSerializer : AssetScalarSerializerBase
{
    public override bool CanVisit(Type type)
    {
        return typeof(System.Uri) == type;
    }

    public override object ConvertFrom(ref ObjectContext context, Scalar fromScalar)
    {
        return new System.Uri(fromScalar.Value);
    }

    public override string ConvertTo(ref ObjectContext objectContext)
    {
        return objectContext.Instance.ToString()!;
    }
}
